<template>
  <div>
      <el-row style="padding:20px;margin-top:20px">
        <el-col :span="24">
          <el-steps :active="step" style="margin-left:20%;font-size:39px;cursor:pointer;">
                <el-step title="步骤 1" style="text-align:center" icon="edit" description="添加记录的基本信息">
                </el-step>
                <el-step title="步骤 2" icon="upload" description="添加图片和视频">
                </el-step>
            </el-steps>
        </el-col>
        <el-col v-if="step==1" :span="14" style="margin-top:30px;margin-left:10%">
           <el-form :model="form" :rules="rules" ref="form" label-width="200px" label-suffix="：">
                <el-form-item v-for="(v,k,i) in form" :label="labels[i]" :key="i" :prop="k">
                    <el-input type="textarea" v-if="k=='inspectContent'" v-model="form[k]"></el-input>
                    <el-input type="textarea" v-else-if="k=='remarks'" v-model="form[k]"></el-input>
                    <el-date-picker type="datetime"  v-else-if="k=='inspectDateTime'" v-model="form[k]"></el-date-picker>
                    <el-input v-else v-model="form[k]" style="width:400px"></el-input>
                </el-form-item>
                <el-form-item align="center">
                    <el-button type="warning">重置</el-button>
                    <el-button type="primary" @click="addNewRecord">添加</el-button>
                </el-form-item>
           </el-form>
        </el-col>
        <el-col v-else-if="step==2" style="margin-top:30px;" :span="18">
          <div style="margin-left:25%">
            <h4>图片上传（支持多图）</h4>
            <el-upload
              class="upload-demo"
              :action="getDomian()+'/msmis/api/Nonpublic/uploadEnterprisePicture?code='+form.enterpriseUSCcode"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :file-list="fileList2"
              :headers="header"
              list-type="picture">
              <el-button size="small" type="primary">点击上传</el-button>
              <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
          </div>
          <div style="margin-left:25%;margin-top:100px;">
            <h4>视频上传</h4>
           <el-upload
             class="upload-demo"
             drag
             :action="getDomian()+'https://jsonplaceholder.typicode.com/posts/'"
             multiple>
             <i class="el-icon-upload"></i>
            <div class="el-upload__text">将视频拖到此处，或<em>点击上传</em></div>
           </el-upload>
          </div>
        </el-col>
        <el-col :span="24">
            <div class="preDiv">
                <i v-if="step!=1" class="fa fa-angle-double-left fa-5x" @click="goPre"></i>
                <div v-if="step!=1" class="directionFont"  @click="goPre">
                    上一步(继续添加信息)
                </div>
            </div>
            <div class="nextDiv">
                <i v-if="step!=2" class="fa fa-angle-double-right fa-5x" @click="goNext"></i>
                <div v-if="step!=2" class="directionFont" @click="goNext">
                    下一步(上传图片)
                </div>
                <i v-if="step==2" class="fa fa-history fa-5x" @click="submit"></i>
                <div v-if="step==2" class="directionFont" @click="submit">
                    完成
                </div>
            </div>
        </el-col>
      </el-row>
  </div>
</template>

<script>
import * as api from '@/api/securityManage'
import {formatDateTime} from "@/utils"
import { getToken } from '../../utils/auth';
export default {
  data() {
    return {
      header:{
        token:getToken()
      },
      mytype: 2,
      flag: 0,
      button: "保存",
      step: 1,
      fileList2: [],
      dialogVisible: false,
      form: {
        inspecterCertID: "", //       char(18) comment '巡查人身份证号',
        inspecterName: "", //         varchar(50) comment '巡查人姓名',
        inspectDateTime: "", //       datetime,
        inspectContent: "", //        varchar(500),
        enterpriseUSCcode: "", //     char(18) comment '所在企业统一社会信用代码',
        remarks: "" //               varchar(500) comment '备注',
      },
      labels: ["巡查人身份证", "巡查人姓名", "巡查日期", "巡查内容", "所查企业统一社会信用代码", "备注"],
      rules: {
        inspecterCertID: [
          { required: true, message: "身份证不得为空!", trigger: "blur" }
        ]
      },
      Codes: []
    };
  },
  methods: {
    getDomian(){
      return 'http://' + window.location.host;
    },
    changeDate(val) {
      if (val != null && val != "") {
        this.form.inspectDateTime = val;
      }
    },
    goPre() {
      this.flag = 0;
      if (this.step > 1) {
        this.step = this.step - 1;
      }
    },
    goNext() {
      //   if(this.flag==0||this.form.sSEventID==''){
      //      this.$notify.error({
      //       title: '错误',
      //       message: '请先您保存基本信息，再添加图片信息！'
      //     });
      //     return
      //   }
      if (this.step < 2) {
        this.step = this.step + 1;
      }
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    submit() {
      this.$router.go(-1);
    },
    addNewRecord(formName) {
      this.form.inspectDateTime = formatDateTime(this.form.inspectDateTime)
      api.addInspectRecord(this.form).then(res => {
        if (res.data) {
          this.$message({
            type: "success",
            message: "添加成功!"
          });
        } else {
          this.$message({
            type: "error",
            message: res.message
          });
        }
      });
    }
  },
  mounted() {
    api.getKeyEnterpriseUSCcode().then(res => {
      this.Codes = res.data;
    });
  }
};
</script>


<style scoped>
.preDiv {
  position: fixed;
  top: 300px;
  left: 10%;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  /* margin-left: 10px; */
}
.nextDiv {
  position: fixed;
  top: 300px;
  right: 0;
  cursor: pointer;
  color: #58b7ff;
  text-align: center;
  margin-right: 10px;
}
</style>
